package com.tz.online.cart;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tz.online.entity.Cart;

/**
 * 接收删除购物车中商品的请求
 * @author Administrator
 *
 */
@WebServlet(name="removeCart",urlPatterns="/cart/removeCart")
public class RemoveCartAction extends HttpServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -9000297079006808175L;

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out = resp.getWriter();
		try {
			String ids = req.getParameter("ids"); //接收删除的商品id
			Cart cart = (Cart) req.getSession().getAttribute("cart");
			
			cart.removeCart(ids);//调用购物车删除逻辑
			
			req.getSession().setAttribute("cart", cart);
			out.print("1");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			out.print("0");
			e.printStackTrace();
		}
	}
}
